<?php
header("Content-type:text/html; charset=utf-8");

class Mysql{
	private $mysql,$result,$result_array_one,$result_array_all,$row;
	
	function __construct(){
		$this->mysql=new PDO("mysql:host=localhost; dbname=cood_books","root","root");
		if(!$this->mysql) exit(0);
		$this->result_array_all=array();
		$this->result_all_one=array();
		$this->mysql->query("set names utf8");
	}
	
	function valiMems($username,$password){
		$select=$this->mysql->prepare("select password from members where username='$username'");
		$select->execute();
		
		$row=$select->fetch(PDO::FETCH_ASSOC);
		if($row['password']==$password){
			return 1;
		}else{
			return 0;
		}
	}
	
	function getPasswd($username){
		$select=$this->mysql->prepare("select * from unpw where username='$username' order by id desc");
		$select->execute();
		while($row=$select->fetch(PDO::FETCH_ASSOC)){
			$this->result_array_one['tag']=$row['tag'];
			$this->result_array_one['un']=$row['un'];
			$this->result_array_one['pw']=$row['pw'];
			$this->result_array_one['id']=$row['Id'];
			
			array_push($this->result_array_all,$this->result_array_one);
		}
		return $this->result_array_all;
		$this->result_array_all=array();
	}
	
	function editItem($id,$tag,$un,$pw){
		$alter=$this->mysql->prepare("update unpw set tag='$tag',un='$un',pw='$pw' where id=$id");
		$status=$alter->execute();
		
		if($status){
			return 1;
		}else{
			return 0;
		}
	}
	
	function addItem($username,$un,$pw,$tag){
		$insert=$this->mysql->prepare("insert into unpw(tag,un,pw,username) values ('$tag','$un','$pw','$username')");
		$status=$insert->execute();
		
		if($status){
			return 1;
		}else{
			return 0;
		}
	}
}


function alert($string){
	echo "<script language='javascript'>";
	echo "alert('$string');";
	echo "</script>";
}

function open($string,$string2){
	echo "<script language='javascript'>";
	echo "window.open('$string','$string2');";
	echo "</script>";
}
?>